<?php

namespace app\master\controller;

use think\Db;
use think\Exception;

class Accounts extends Base
{
    //汽车结算
    public function caraccounts()
    {
        $data['start_date'] = input('start_date');
        $data['end_date'] = input('end_date');
        $data['company_id'] = input('company_id');
        if (request()->isGet()) {
            $company = db('company')->where(["company_status"=>1,"pid"=>0])->field("company_id,company_name")->select();
            $this->assign('company', $company);
            $this->assign('data', $data);
            return $this->fetch('caraccounts');
        }
        $where = [];
        if ($data['company_id']) $where['c.company_id'] = $data['company_id'];
        if ($data['start_date']) {
            $where['c.contractcar_bigontime'] = ['egt', strtotime($data['start_date'])];
        }
        if ($data['end_date']) {
            $where['c.contractcar_endtime'] = ['elt', strtotime($data['end_date'])];
        }
        $where = [
            "c.contractcar_type"=>3,
            "c.contractcar_status"=>4,
        ];
        $page = input('page');
        $limit = input('limit');
        $list = model('Accounts')->getcaraccountslist($where, $page, $limit);
        return $this->tableReturn(0, '查询成功', $list['count'], $list['data']);
    }
    //驾驶员结算
    public function driveaccounts()
    {
        $data['start_date'] = input('start_date');
        $data['end_date'] = input('end_date');
        $data['company_id'] = input('company_id');
        if (request()->isGet()) {
            $company = db('company')->where(["company_status"=>1,"pid"=>0])->field("company_id,company_name")->select();
            $this->assign('company', $company);
            $this->assign('data', $data);
            return $this->fetch('driveaccounts');
        }
        $where = [];
        if ($data['company_id']) $where['d.company_id'] = $data['company_id'];
        if ($data['start_date']) {
            $where['c.start_time'] = ['egt', strtotime($data['start_date'])];
        }
        if ($data['end_date']) {
            $where['c.end_time'] = ['elt', strtotime($data['end_date'])];
        }
        $where = [
            "c.contractcar_type"=>2,
            "c.contractcar_status"=>4,
        ];
        $page = input('page');
        $limit = input('limit');
        $list = model('Accounts')->getdriveaccountslist($where, $page, $limit);
        return $this->tableReturn(0, '查询成功', $list['count'], $list['data']);
    }
    //派车结算记录
    public function caraccountsinfo(){
        if (request()->isGet()) {
            return $this->fetch('caraccountsinfo');
        }
        $where = [
            "c.contractcar_type"=>3,
            "c.contractcar_status"=>4,
        ];
        $page = input('page');
        $limit = input('limit');
        $list = model('Accounts')->getcaraccountsinfo($where, $page, $limit);
        return $this->tableReturn(0, '查询成功', $list['count'], $list['data']);
    }
}